'use strict';
const BaseController = require('./base');
const serviceName = 'user';
// 继承baseController 并且指定serviceName
class RouterController extends BaseController {
  constructor(ctx) {
    super(ctx, serviceName);
  }

  getListQuery(query) {
    let where = {}
    return where
  }

  async login() {
    const { ctx } = this;
    const { username, password } = ctx.request.body;
    const res = await ctx.service[this.serviceName].login(username, password);
    this.ctx.success(res);
  }
  async register() {
    const { ctx } = this;
    const { username, password } = ctx.request.body;
    const res = await ctx.service[this.serviceName].register(username, password);
    this.ctx.success(res);
  }

  async getUserRoles() {
    const { ctx } = this;
    const { userId } = ctx.query;
    const res = await ctx.service[this.serviceName].getUserRoles(userId);
    this.ctx.success(res);
  }
  async updateUserRoles() {
    const { ctx } = this;
    const { userId, roleIds } = ctx.request.body;
    const res = await ctx.service[this.serviceName].updateUserRoles({userId, roleIds});
    this.ctx.success(res);
  }

  async getUserInfo() {
    const { ctx } = this;
    const { userId } = ctx.query;
    const res = await ctx.service[this.serviceName].getUserInfo(userId);
    this.ctx.success(res);
  }
}
module.exports = RouterController;
